<template>
  <div class="common-layout">
    <el-container>
      <el-header>Header</el-header>
      <el-container>
        <el-aside width="200px">Aside</el-aside>
        <el-container>
          <el-main>
            <el-space >
              <el-button type="primary" :icon="Edit"  />
              <el-button type="primary" :icon="Share" />
              <el-button type="primary" :icon="Delete" />
              <el-button type="primary" @click="store.increment" >加起来</el-button>
              <el-button type="primary" @click="getUser" >获取用户</el-button>
              <el-text class="mx-1" type="primary">{{store.getUsername}}</el-text>
              <el-text class="mx-1" type="primary">{{count}}   </el-text>

              <el-radio-group v-model="direction">
                <el-radio label="ltr">left to right</el-radio>
                <el-radio label="rtl">right to left</el-radio>
                <el-radio label="ttb">top to bottom</el-radio>
                <el-radio label="btt">bottom to top</el-radio>
              </el-radio-group>
              <!-- <el-text class="mx-1" type="primary">{{data}}</el-text> -->
           </el-space>
          </el-main>
          <el-footer>Footer</el-footer>
        </el-container>
      </el-container>
    </el-container>
  </div>
  <el-drawer
    v-model="drawer"
    title="I am the title"
    :direction="direction"
    :before-close="handleClose"
  >
    <span>{{data}}</span>
  </el-drawer>
</template>
<script scoped lang="ts">
  import { defineComponent, ref } from 'vue'
  import {Edit,Share,Delete} from '@element-plus/icons-vue'
  import {ElMessageBox} from 'element-plus'
  import {useCounterStore} from '../src/stores/counter'
  import { storeToRefs } from 'pinia'
  import {user} from '../src/model/User'
  export default defineComponent({
    name: 'layOut',
    methods: {
      async getUser(){
        const result= await user.getUser(1);
        this.data=result.data;
        this.drawer = true;
      },
     
      handleClose(done:any){
       
          ElMessageBox.confirm('Are you sure you want to close this?')
          .then(() => {
            done()
          }).catch(() => {
          // catch error
         })
      }
    },
    props: {

    },
    components: {
      Edit,Share,Delete
    },
    setup () {
      //使用pinia
      const drawer = ref(false)
      const store=useCounterStore();
      const data=ref();
      const {username, password,count} =storeToRefs(store);
      store.username="binson";
      const direction = ref('rtl');
      return {Edit,Share,Delete,username,password,count,store,data,drawer,direction }
    },
    watch: {}
})

</script>
<style scoped>
.common-layout {
  background-color: var(--el-color-primary-light-7);
  color: var(--el-text-color-primary);
}
.el-header, .el-footer {
    background-color: #B3C0D1;
    color: #333;
    text-align: left;
    line-height: 60px;
}

.el-aside {
    background-color: #D3DCE6;
    color: #333;
    text-align: center;
    line-height: 760px;
}

.el-main {
    background-color: #E9EEF3;
    color: #333;
    text-align: center;
    line-height: 700px;
}
</style>